package tests;

import common.Utils;
import org.openqa.selenium.By;
import org.openqa.selenium.support.ui.ExpectedConditions;

public class ListPage extends Utils {
    public static String url = "http://8.137.19.140:9090/blog_list.html";

    public ListPage() {
        super(url);
    }

    /**
     * 检查博客列表----三个模块（个人信息模块、博客列表模块、菜单模块）
     * 博客列表模块
     */
    public void checkBlogList(){
        //博客标题
        String title = driver.findElement(By.cssSelector("body > div.container > div.right > div:nth-child(1) > div.title")).getText();
        //博客发布时间
        String pushTime = driver.findElement(By.cssSelector("body > div.container > div.right > div:nth-child(1) > div.date")).getText();
        //博客内容
        String content = driver.findElement(By.cssSelector("body > div.container > div.right > div:nth-child(1) > div.desc")).getText();
        //查看全文按钮
        String button = driver.findElement(By.cssSelector("body > div.container > div.right > div:nth-child(1) > a")).getText();

        //校验文本
        assert !title.isEmpty();
        assert !pushTime.isEmpty();
        assert !content.isEmpty();
        assert button.equals("查看全文>>");
    }

    /**
     * 查看全文按钮的跳转
     */
    public void checkBtnJump() throws InterruptedException {
        //获取列表页博客标题
        String title = driver.findElement(By.cssSelector("body > div.container > div.right > div:nth-child(1) > div.title")).getText();
        //点击查看全文按钮实现跳转
        driver.findElement(By.cssSelector("body > div.container > div.right > div:nth-child(1) > a")).click();
//        Thread.sleep(1000);
        // 使用显式等待等待详情页标题元素出现
        wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("body > div.container > div.right > div > div.title")));
        //获取详情页博客标题
        String jumpTitle = driver.findElement(By.cssSelector("body > div.container > div.right > div > div.title")).getText();
        System.out.println(jumpTitle);

        //校验
        assert jumpTitle.equals(title);

        //保存一份
        detailUrl = driver.getCurrentUrl();
    }
}





































